package com.example.demo;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import io.micrometer.common.util.StringUtils;
import lombok.Builder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomUtils;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Slf4j
public class Test {

    // AES 加密
    public static String encrypt(String plainText, String key) throws Exception {
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        SecretKeySpec secretKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        byte[] encryptedBytes = cipher.doFinal(plainText.getBytes("UTF-8"));
        return Base64.getEncoder().encodeToString(encryptedBytes);
    }

    // AES 解密
    public static String decrypt(String encryptedText, String key) throws Exception {
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        SecretKeySpec secretKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedText));
        return new String(decryptedBytes, "UTF-8");
    }


    public static void caiyao_detail() throws Exception {
        File directory = new File("/Users/jing/Documents/food_data/caiyao/");
        for (File file:directory.listFiles()) {
            JSONObject fileResult = JSONObject.parseObject(FileUtils.readFileToString(file, "UTF-8"));
            JSONArray list = fileResult.getJSONObject("result").getJSONArray("list");

            List<JSONObject> items = list.toJavaList(JSONObject.class);
            for (JSONObject item : items) {
                TimeUnit.SECONDS.sleep(RandomUtils.nextInt(2, 7));

                String sid = item.getString("id");
                Map<String, String> param = new HashMap<>();
                param.put("aid", "2");
                param.put("id", sid);

                String url = "https://www.nutridata.cn/api/nutri-service/dish/selectFoodById";
                String json = JSON.toJSONString(param);
                String encrypt = encrypt(json, secretKey);
                log.info(encrypt);
                log.info(decrypt(encrypt,secretKey));
                String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
                log.info(decrypt(result, secretKey));
                String content = decrypt(result, secretKey);


                if (!content.contains("成功")) {
                    throw new RuntimeException("请求失败");
                }
                String image = JSONObject.parseObject(content).getJSONObject("result").getString("image");
                System.out.println(image);
                if(StringUtils.isNotBlank(image)){
                    downloadImage(image,"/Users/jing/Documents/food_data/caiyao20240719_image" , sid+".jpg");
                }
                FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/caiyao_detail/" + sid + ".txt"), content);
            }
            FileUtils.moveFile(file, new File("/Users/jing/Documents/food_data/caiyao_finished/" + file.getName()));

        }

    }

    public static void downloadImage(String imageUrl, String saveDirectory, String filename) {
        InputStream inputStream = null;
        FileOutputStream fileOutputStream = null;
        HttpURLConnection connection = null;

        try {
            // 对URL进行编码处理
            URL url = new URL(imageUrl);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("User-Agent", "Mozilla/5.0");
            connection.connect();

            // 检查响应码
            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new IOException("HTTP response code: " + connection.getResponseCode());
            }

            // 确保保存目录存在
            File directory = new File(saveDirectory);
            if (!directory.exists()) {
                directory.mkdirs();
            }

            // 创建文件输出流
            File file = new File(directory, filename);
            fileOutputStream = new FileOutputStream(file);

            // 获取输入流并写入文件
            inputStream = new BufferedInputStream(connection.getInputStream());
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                fileOutputStream.write(buffer, 0, bytesRead);
            }

            System.out.println("Image successfully downloaded: " + file.getAbsolutePath());

        } catch (IOException e) {
            System.err.println("Error downloading image: " + e.getMessage());
        } finally {
            // 关闭资源
            try {
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
                if (inputStream != null) {
                    inputStream.close();
                }
                if (connection != null) {
                    connection.disconnect();
                }
            } catch (IOException e) {
                System.err.println("Error closing resources: " + e.getMessage());
            }
        }
    }

    public static void shicai_detail() throws Exception {
        File directory = new File("/Users/jing/Downloads/shicai20240719/");
        for (File file:directory.listFiles()) {
            JSONObject fileResult = JSONObject.parseObject(FileUtils.readFileToString(file, "UTF-8"));
            JSONArray list = fileResult.getJSONObject("result").getJSONArray("list");

            List<JSONObject> items = list.toJavaList(JSONObject.class);
            for (JSONObject item : items) {
                TimeUnit.SECONDS.sleep(RandomUtils.nextInt(3, 10));

                String sid = item.getString("id");
                Map<String, String> param = new HashMap<>();
                param.put("aid", "2");
                param.put("id", sid);

                String url = "https://www.nutridata.cn/api/nutri-service/ingredient/selectIngredientById";
                String json = JSON.toJSONString(param);
                String encrypt = encrypt(json, secretKey);
                log.info(encrypt);
                log.info(decrypt(encrypt,secretKey));
                String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
                log.info(decrypt(result, secretKey));
                String content = decrypt(result, secretKey);


                if (!content.contains("成功")) {
                    throw new RuntimeException("请求失败");
                }
                String image = JSONObject.parseObject(content).getJSONObject("result").getString("image");
                System.out.println(image);
                if(StringUtils.isNotBlank(image)){
                    downloadImage(image,"/Users/jing/Downloads/shicai20240719_image" , sid+".jpg");
                }
                FileUtils.writeStringToFile(new File("/Users/jing/Downloads/shicai20240719_detail/" + sid + ".txt"), content);
            }
            FileUtils.moveFile(file, new File("/Users/jing/Downloads/shicai20240719_detail_finished/" + file.getName()));

        }

    }

    public static void caiyao_list() throws Exception {
        for (int i = 2016; i <= 2218; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/dish/selectFoodList";
            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(1l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Downloads/caiyao/" + page + ".txt"), decrypt(result, secretKey));
        }
    }


    public static void shicai_list() throws Exception {
        for (int i = 1; i <= 325; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/ingredient/selectIngredientList";
            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(1l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/shicai20240719/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    public static void gi_detail() throws Exception {
        File directory = new File("/Users/jing/Documents/food_data/gi_list/");
        for (File file:directory.listFiles()) {
            JSONObject fileResult = JSONObject.parseObject(FileUtils.readFileToString(file, "UTF-8"));
            JSONArray list = fileResult.getJSONObject("result").getJSONArray("list");

            List<JSONObject> items = list.toJavaList(JSONObject.class);
            for (JSONObject item : items) {
                TimeUnit.SECONDS.sleep(RandomUtils.nextInt(3, 10));

                String sid = item.getString("id");
                Map<String, String> param = new HashMap<>();
                param.put("aid", "7");
                param.put("id", sid);

                String url = "https://www.nutridata.cn/api/nutri-service/giFood/selectGIFoodById";
                String json = JSON.toJSONString(param);
                String encrypt = encrypt(json, secretKey);
                log.info(encrypt);
                log.info(decrypt(encrypt,secretKey));
                String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
                log.info(decrypt(result, secretKey));
                String content = decrypt(result, secretKey);


                if (!content.contains("成功")) {
                    throw new RuntimeException("请求失败");
                }
                String image = JSONObject.parseObject(content).getJSONObject("result").getString("image");
                System.out.println(image);
                if(StringUtils.isNotBlank(image)){
                    downloadImage(image,"/Users/jing/Documents/food_data/gi_image" , sid+".jpg");
                }
                FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/gi_detail/" + sid + ".txt"), content);
            }
            FileUtils.moveFile(file, new File("/Users/jing/Documents/food_data/gi_finished/" + file.getName()));

        }

    }

    public static void gi_list() throws Exception {
        for (int i = 1; i <= 396; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/giFood/selectGIFoodList";
            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(7l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/gi_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    /**
     * 补剂
     * @throws Exception
     */
    public static void supply_list() throws Exception {
        for (int i = 1; i <= 1863; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/supplyment/selectSupplymentList";
            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(7l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/supply_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    /**
     * 保健品
     */
    public static void baojian_list() throws Exception {
        for (int i = 1864; i <= 2477; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/healthfood/selectHealthfoodList";
            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(8l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/baojian_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }


    /**
     * 奶粉
     */
    public static void naifen_list() throws Exception {
        for (int i = 1; i <= 232; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/babyFormula/selectBabyFormulaList";
            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(3l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/naifen_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    /**
     * 特殊医学用途配方食品
     * @throws Exception
     */
    public static void spical_yxyt_list() throws Exception {
        for (int i = 1; i <= 20; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/special/selectBabyFormulaSpecialList";
            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(3l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/特殊医学用途配方食品_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    /**
     * 功能食品原料
     */
    public static void gongnengshipin_list() throws Exception {
        for (int i = 1; i <= 20; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/functionalFood/selectFunctionalFoodList";
            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(3l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/功能食品原料_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    /**
     * 氨基酸库
     */
    public static void anjisuan_list() throws Exception {
        for (int i = 1; i <= 101; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";
            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(10l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/氨基酸库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    /**
     * 脂肪酸库
     * "typeName":"基础组成","id":11
     */
    public static void fat_list() throws Exception {
        for (int i = 1; i <= 110; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().typeName("基础组成").page(page).pageSize(10).id(11l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/脂肪酸库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }


    /**
     * 大豆异黄酮成分库
     * "typeName":"基础组成",cccccccccccccccssssscid":11
     */
    public static void dadou_list() throws Exception {
        for (int i = 1; i <= 28; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().typeName("基础组成").page(page).pageSize(10).id(12l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/大豆异黄酮成分库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    /**
     * 植物甾醇数据库
     * "typeName":"基础组成",cccccccccccccccssssscid":11
     */
    public static void zhiwuzichun_list() throws Exception {
        for (int i = 1; i <= 10; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(13l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/植物甾醇数据库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }


    /**
     * 胡萝卜素
     * "typeName":"基础组成",cccccccccccccccssssscid":11
     */
    public static void huluobosu_list() throws Exception {
        for (int i = 1; i <= 10; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(14l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/胡萝卜素_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    /**
     * USDA胆碱数据库
     */
    public static void danjian_list() throws Exception {
        for (int i = 1; i <= 28; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(15l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/USDA胆碱数据库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }


    /**
     * 类黄铜
     */
    public static void huangtong_list() throws Exception {
        for (int i = 1; i <= 28; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(16l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/类黄铜_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }


    /**
     * 花青素数据库
     */
    public static void qinghuasu_list() throws Exception {
        for (int i = 1; i <= 15; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(17l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/花青素数据库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }


    /**
     * 白藜芦醇数据库
     */
    public static void 白藜芦醇数据库_list() throws Exception {
        for (int i = 1; i <= 21; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(18l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/白藜芦醇数据库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }



    /**
     * 叶黄素库
     */
    public static void 叶黄素库_list() throws Exception {
        for (int i = 1; i <= 31; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(19l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/叶黄素库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }


    /**
     * 番茄红素库
     */
    public static void 番茄红素库_list() throws Exception {
        for (int i = 1; i <= 6; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/specialFood/selectSpecialFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(20l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/番茄红素库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }



    /**
     * 代餐食品数据库
     */
    public static void 代餐食品数据库_list() throws Exception {
        for (int i = 1; i <= 29; i++) {
            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(5, 10));
            int page = i;
            String url = "https://www.nutridata.cn/api/nutri-service/replacementFood/selectReplacementFoodList";

            String json = JSON.toJSONString(ReqPageData.builder().page(page).pageSize(10).id(21l).build());
            String encrypt = encrypt(json, secretKey);

            String result = OkHttpClientUtils.postWithHeader(url, encrypt, getHeader());
            log.info(decrypt(result, secretKey));
            FileUtils.writeStringToFile(new File("/Users/jing/Documents/food_data/代餐食品数据库_list/" + page + ".txt"), decrypt(result, secretKey));
        }
    }

    private static String secretKey = "WeQSvK6dN07pZKjb";

    private static String Nutridata_Random = "dxmj1e+4/ZWCOatRZm2gPeHMfA+6BEcV2dXEsS5LF87IUMOwjnxErnE73o0SKh8isgvwgkwRyTZxharx4UiqQ//N4FvK87sbgC62bzzPXFdeLFnckUJ0cDK153XvwueyHCdRXrs8viswIPlRY0d1QYimow4IDN3aOViIcHIlueo=";

    private static String Nutridata_Token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJiNmRkZmFjZTk0NTg0MDJjODZiNTBkMWYzNDNkYmI4MiIsInN1YiI6IjM1MjYiLCJpc3MiOiJzZyIsImlhdCI6MTcyMzc3NTM2OCwiZXhwIjoxNzIzODA0MTY4fQ.2VsiLg19OqTi3cC2Xf2YVGV3wJQh-eXJ9_rfwDftWx8";




    private static Map<String, String> getHeader() {
        Map<String, String> header = new HashMap<>();
        header.put("Nutridata-Random",Nutridata_Random);
        header.put("Nutridata-Token", Nutridata_Token);
        header.put("Host", "www.nutridata.cn");
        header.put("Content-Type", "application/json");
        header.put("Content-Length", "44");
        header.put("Connection", "keep-alive");
        header.put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");
//        header.put("Accept-Encoding", "gzip, deflate, br, zstd");
        header.put("Accept", "application/json, text/plain, */*");
        header.put("Origin", "https://www.nutridata.cn");
        header.put("Referer", "https://www.nutridata.cn/database/list?id=2&date="+System.currentTimeMillis());
        header.put("Sec-Ch-Ua", "Microsoft Edge\";v\"125\", \"Chromium\";v=\"125\", \"Not.A/Brand\";v=\"24\"");
        header.put("Sec-Ch-Ua-Mobile", "?0");
        header.put("Sec-Ch-Ua-Platform", "macOS");
        header.put("Sec-Fetch-Dest", "empty");
        header.put("Sec-Fetch-Mode", "cors");
        header.put("Sec-Fetch-Site", "same-origin");
        header.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0");
        return header;
    }

    @Builder
    @Data
    public static class ReqPageData {

        private Integer page;

        private Integer pageSize;

        private Long id;

        private String typeName;
    }


    public static void main(String[] args) throws Exception {


//        System.out.println(decrypt("fB82zRWqh7xQKbgWO172W/XvsmVvreszBn2uHDrCcZqFjnDmGdY5ytW99D7q0YSm",secretKey));
//        caiyao_detail();
//        shicai_list();
//        shicai_detail();

//        downloadImage("https://oss.dyhomedr.com/image/ingredient/1797-%E5%86%B0%E7%B3%96.jpg?Expires=1722497730&OSSAccessKeyId=LTAI5tDFrWnVZcGYUii5K3bw&Signature=t0590yepkx5a%2FVKoJN9MRaU1kq4%3D", "/Users/jing/Downloads/shicai20240719_image_01", "20230719_0.jpg");

//        System.out.println(decrypt("eCEKjGmnQbWLSNMEZ3yhA23ZW8AgUC3Gj+LoSgkmnU17SNgQL3kXiTEUHI/pKPxh",secretKey));

//          gi_list();
//        gi_detail();

//        supply_list();
//          baojian_list();
//          naifen_list();
//        spical_yxyt_list();
//        gongnengshipin_list();
//        anjisuan_list();
//        fat_list();
//        dadou_list();
//        zhiwuzichun_list();
//        huluobosu_list();
//        danjian_list();
//        huangtong_list();
//        qinghuasu_list();
//        白藜芦醇数据库_list();
//        叶黄素库_list();
//        番茄红素库_list();
        代餐食品数据库_list();
    }
}
